package com.sale.system.controller;

import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.system.domain.AccountsEmpty;
import com.sale.system.domain.PullDown;
import com.sale.system.domain.SysParameterDescription;
import com.sale.system.domain.dto.SysAccountsDetailsDto;
import com.sale.system.domain.dto.SysAccountsDto;
import com.sale.system.domain.vo.SysAccountsUpdateVo;
import com.sale.system.domain.vo.SysAccountsVo;
import com.sale.system.domain.vo.SysFunctionalParameterVo;
import com.sale.system.domain.vo.SysInventoryAccountingVo;
import com.sale.system.service.ISysAccountsService;
import com.sale.system.service.ISysParameterDescriptionService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 账套管理
 * @Param SetAccounts
 * @Date 23-07-07
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/accounts")
public class SysAccountsController extends BaseController {

    private final ISysAccountsService sysAccountsService;

    private final ISysParameterDescriptionService sysParameterDescriptionService;

    /**
     * 账套信息系统参数集合
     */
    //@SaCheckPermission("system:toolCode:list")
    @GetMapping("/selectAccountsDetailsList")
    public R<SysAccountsDetailsDto> selectAccountsDetailsList(Long accountsId)
    {
        SysAccountsDetailsDto sysAccountsDetailsDto = sysAccountsService.selectAccountsDetailsList(accountsId);
        return R.ok(sysAccountsDetailsDto);
    }

    /**
     * 查询账套管理
     */
    //@SaCheckPermission("system:accounts:list")
    @GetMapping("/list")
    public R<List<SysAccountsDto>> list()
    {
        List<SysAccountsDto> list = sysAccountsService.selectAccountsList();
        return R.ok(list);
    }

    /**
     * 新增账套管理
     */
   // //@SaCheckPermission("system:zhangSet:add")
    @Log(title = "账套管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysAccountsVo sysAccountsVo) {
        return toAjax(sysAccountsService.insertAccounts(sysAccountsVo));
    }

    /**
     * 修改账套管理
     */
    //@SaCheckPermission("system:zhangSet:edit")
    @Log(title = "账套管理", businessType = BusinessType.INSERT)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody SysAccountsUpdateVo sysAccountsUpdateVo) {
        return toAjax(sysAccountsService.updateAccounts(sysAccountsUpdateVo));
    }

    /**
     * 修改功能参数
     */
    //@SaCheckPermission("system:accounts:updateSysFunctionalParameter")
    @Log(title = "修改功能参数", businessType = BusinessType.INSERT)
    @PutMapping("/updateSysFunctionalParameter")
    public R<Void> updateSysFunctionalParameter(@Validated @RequestBody List<SysFunctionalParameterVo> sysFunctionalParameterVo) {
        return toAjax(sysAccountsService.updateSysFunctionalParameter(sysFunctionalParameterVo));
    }

    /**
     * 修改库存核算
     */
    //@SaCheckPermission("system:accounts:updateSysInventoryAccounting")
    @Log(title = "修改库存核算", businessType = BusinessType.INSERT)
    @PutMapping("/updateSysInventoryAccounting")
    public R<Void> updateSysInventoryAccounting(@Validated @RequestBody SysInventoryAccountingVo sysInventoryAccountingVo) {
        return toAjax(sysAccountsService.updateSysInventoryAccounting(sysInventoryAccountingVo));
    }

    /**
     * 删除账套管理
     */
    //@SaCheckPermission("system:zhangSet:remove")
    @Log(title = "账套管理", businessType = BusinessType.INSERT)
    @DeleteMapping("/{accountsId}")
    public R<Void> remove(@PathVariable long accountsId) {
        return toAjax(sysAccountsService.deleteAccounts(accountsId));
    }

    /**
     * 查询账套
     */
    @GetMapping("/{id}")
    public void tenant(@PathVariable String id)
    {
        sysAccountsService.selectTenant(id);
    }

    /**
     * 新增账套管理
     */
    ////@SaCheckPermission("system:zhangSet:add1")
    @Log(title = "新增参数说明", businessType = BusinessType.INSERT)
    @PostMapping("/addList")
    public R<Void> addList(@Validated @RequestBody SysParameterDescription sysParameterDescription) {
        return toAjax(sysParameterDescriptionService.insertParameterDescription(sysParameterDescription));
    }

    /**
     * 无账套的情况下(新增)
     */
    @PostMapping("/addEmpty")
    public R<Void> addEmpty(@Validated @RequestBody AccountsEmpty accountsEmpty) {
        return toAjax(sysAccountsService.insertAccountsEmpty(accountsEmpty));
    }

    /**
     * 账套下拉
     */
    @GetMapping("/accountsDown")
    public List<PullDown> accountsDown() {
        return sysAccountsService.accountsDown();
    }

}
